package com.hotelmanage.hm.controller;

import com.hotelmanage.hm.service.HotelService;
import com.hotelmanage.hm.vo.HotelVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/hotel")
public class HotelController {

    @Autowired
    private HotelService hotelService;

    @RequestMapping("getHotel")
    public Object get(){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("hotel",hotelService.getHotel());
        return map;
    }

    @RequestMapping("getHotelById")
    public Object getHotelById(@RequestParam int hotelid){
        Map<String,Object> map = new HashMap<String, Object>();


        map.put("hotel",hotelService.getById(hotelid));
        return map;
    }

    @RequestMapping("newHotel")
    public Object newHotel(@RequestBody HotelVO hotelVO){
        Map<String,Object> map = new HashMap<String, Object>();


        int result = hotelService.newHotel(hotelVO);
        if(result==0){
            map.put("status",404);
            map.put("desc","新增失败");
        }else{
            map.put("status",200);
            map.put("desc","新增成功");
        }
        return map;
    }

    @RequestMapping("editHotel")
    public Object editHotel(@RequestBody HotelVO hotelVO){
        Map<String,Object> map = new HashMap<String, Object>();


        int result = hotelService.editHotel(hotelVO);
        if(result==0){
            map.put("status",404);
            map.put("desc","编辑失败");
        }else{
            map.put("status",200);
            map.put("desc","编辑成功");
        }
        return map;
    }

    @RequestMapping("deleteHotel")
    public Object deleteHotel(@RequestParam int hotelid){
        Map<String,Object> map = new HashMap<String, Object>();


        int result = hotelService.deleteHotel(hotelid);
        if(result==0){
            map.put("status",404);
            map.put("desc","删除失败");
        }else{
            map.put("status",200);
            map.put("desc","删除成功");
        }
        return map;
    }
}
